#include <stdio.h>
#include <stdlib.h>

#include "network/network.h"
#include "bfs/bfs.h"

#define NODO 35
#define LENGTH(x) x[0]

/** Procedimiento principal */
int main (void){

    long int node_1, node_2, cap, error, i;
    Tuple t = NULL;
    Network n = NULL;
    long int *path;
    
    n = network_create();
    error = 3;
        
    while (error==3)
    {
        if(error == 3)
        {
            error = scanf("%li %li %li", &node_1, &node_2, &cap);

            if (error == 3)
            {
                /*printf("%i %i %i error %i \n", node_1, node_2, cap, error);*/
                t = tuple_fromKeyData(node_2,cap);
                network_add_node(n,node_1,t);
                t = tuple_destroy(t);
                t = NULL;
        
            }
        }
    }
    
    path = BFS_minimum_path(n);
    
    if (path == NULL)
    {
        printf("No existe el camino :'(\n");
    }
    else
    {
        printf("Existe el camino: ");
        for (i = 2; i <= path[0] + 1; i++)
        {
        printf("%li ", path[i]);
        }
        printf("\n");
        printf("Con flujo: %li\n", path[1]);
    }
    
    free(path);
    n = network_destroy(n);
    
    return 0;
}
